<?php
declare (strict_types = 1);
namespace app\index\middleware;

//Aaa 中间件
// +----------------------------------------------------------------------
// | handle()                     处理(请求头、token等)
// | recursive()                  递归
// +----------------------------------------------------------------------

class Aaa
{
    public function handle($request, \Closure $next)
    {
        //允许所有ip访问，设置请求类型
        header("Access-Control-Allow-Origin: *");
        header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
        header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');

        //判断是否 不是登录页面
        if(!preg_match("/login/", $request->pathinfo())) {
            //判断    如果没有session or cookies 跳转到登录页面
            //return redirect((string) url('login/index'));
        }

        //获取请求头
        $info = Request::instance()->header();
        //判断token
        if(isset($info['token'])){
            //有token
        }else{
            //无token
            return json('无token',400);
        }
    }
}

